package com.haiyou.dc.netty.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.haiyou.common.util.R;
import com.haiyou.dc.netty.entity.ImFriendApply;
import com.haiyou.dc.netty.service.ImFriendApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

/**
 * @author root
 * @date 2020-03-04 16:05:17
 */
@RestController
@RequestMapping("/imFriendApply")
@Slf4j
@Api(tags = "朋友申请表")
public class ImFriendApplyController {
    @Autowired
    private ImFriendApplyService imFriendApplyService;

    @ApiOperation(value = "保存数据")
    @PutMapping("/save")
    public R save(@RequestBody ImFriendApply imFriendApply) {
        imFriendApplyService.insertSelective(imFriendApply);
        return R.ok();
    }

    @ApiOperation(value = "查看数据")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        ImFriendApply imFriendApply = imFriendApplyService.selectByPrimaryKey(id);
        return R.ok(imFriendApply);
    }

    @ApiOperation(value = "修改数据")
    @PostMapping("/update")
    public R update(@RequestBody ImFriendApply imFriendApply) {
        imFriendApplyService.updateByPrimaryKeySelective(imFriendApply);
        return R.ok();
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Integer id) {
        imFriendApplyService.deleteByPrimaryKey(id);
        return R.ok();
    }

    @ApiOperation(value = "查看列表数据")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public R list(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        Example example = new Example(ImFriendApply.class);
        example.orderBy("id").desc();
        Page<ImFriendApply> page = PageHelper.startPage(pageNum, pageSize, true, false, false);
        imFriendApplyService.selectByExample(example);
        PageInfo<ImFriendApply> info = new PageInfo<>(page.getResult());
        return R.ok(info);
    }

}